import { defineStore } from 'pinia'
import { getStaffList, getSelectList } from "@/api/staff"
export const useStore = defineStore('counter', {
  state: () => {
    let Much: any = []
    let userData: any = {}
    return {
      ruleleftid: 1,
      tableData: [],
      total: 0,
      ruleLeft: [],
      dialogVisible: false,
      alerttitle: '',
      infoId: '',
      rolelists: {
        id: '',
        name: '',
        state: '',
        description: ''
      },
      SocialData: {
        page: 1,
        pageSize: 0,
        departmentChecks: [],
        providentFundChecks: [],
        socialSecurityChecks: []
      },
      deptID: [],
      departmentChecks: [],
      approvalsTypeChecks: [],
      pointarr: [],
      companylists: {
        id: '',
        name: '',
        address: '',
        phone: '',
        radius: 500,
        point: []
      },
      companynewlist: [],
      Much,
      userData
    }
  },
  getters: {

  },
  actions: {
    //员工表格数据
    render(currentPage1: number, pagesize: number, keyword: string, ruleleftid: number) {
      getStaffList(currentPage1, 10, keyword, ruleleftid).then(res => {
        this.$state.tableData = res.data.data.rows;
        this.$state.total = res.data.data.total;
      })
    },
    render2() {
      getSelectList().then(res => {
        this.getDD(res.data.data)
        this.$state.ruleLeft = this.getDD(res.data.data);
      })
    },
    getDD(data: any, id = 0) {
      let arr1: any = [];
      let arr2: any = [];
      data.forEach((item: any) => {
        if (item.pid == id) {
          arr2 = this.getDD(data, item.id);
          if (arr2.length > 0) {
            item.children = arr2;
          }
          arr1.push(item);
        }
      });
      return arr1;
    }
  }
})